{template 'public/header'}
<link rel="stylesheet" href="{$_W['siteroot']}addons/we7_wmall/resource/web/css/back.css">
<ul class="nav nav-tabs">
	<li {if $op == 'ptcategory'}class="active"{/if}><a href="{php echo $this->createWebUrl('ptcategory');}">添加驿站商品分类</a></li>
	<li><a href="{php echo $this->createWebUrl('ptgoods',array('op'=>'list'));}">驿站商品列表</a></li>
</ul>
{if $op == 'post'}
<form class="form-horizontal form" id="form1" action="" method="post" enctype="multipart/form-data">
	<input type="hidden" name="sid" value="{$sid}">
	<div class="main">
		<div class="panel panel-default">
			<div class="panel-heading">添加驿站商品分类</div>
			<div class="panel-body">
				<div id="tpl">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="require">* </span>分类名称</label>
						<div class="col-sm-9 col-xs-12">
							<input type="text" class="form-control" name="title[]" value="">
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">分类排序</label>
						<div class="col-sm-9 col-xs-12">
							<input type="text" class="form-control" name="displayorder[]" value="">
						</div>
					</div>
					<hr>
				</div>
				<div id="tpl-container"></div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分类排序</label>
					<div class="col-sm-9 col-xs-12" style="padding-top:7px">
						<a href="javascipt:;" id="post-add"><i class="fa fa-plus-circle"></i> 继续添加</a>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-9 col-xs-9 col-md-9">
				<input type="hidden" name="token" value="{$_W['token']}">
				<input name="submit" id="submit" type="submit" value="提交" class="btn btn-primary col-lg-1">
			</div>	
		</div>
	</div>
</form>
<script type="text/javascript">
	require(['util'], function(u){
		$('#post-add').click(function(){
			$('#tpl-container').append($('#tpl').html());
		});
	});
</script>
{elseif $op == 'list'}
<div class="main">
	<div class="panel panel-default">
		<div class="panel-body">
			<a class="btn btn-primary" href="{php echo $this->createWebUrl('ptcategory', array('op' => 'post'));}"/><i class="fa fa-plus-circle"> </i> 添加驿站商品分类</a>
		</div>
	</div>

	<form class="form-horizontal" action="" method="post">
		<div class="panel panel-default">
			<div class="panel-body table-responsive">
				<table class="table table-hover">
					<thead class="navbar-inner">
						<tr>
							<th>分类名称</th>
							<th>排序</th>
							<th>商品数</th>
							<th>是否显示</th>
							<th style="width:150px; text-align:right;">操作</th>
						</tr>
					</thead>
					<tbody>
						{loop $lists $item}
						<tr>
							<input type="hidden" name="ids[]" value="{$item['id']}">
							<td><input type="text" style="width:130px" name="title[]" class="form-control" value="{$item['title']}"></td>
							<td><input type="text" style="width:100px" name="displayorder[]" class="form-control" value="{$item['displayorder']}"></td>
							<td>{php echo intval($nums[$item['id']]['num'])}</td>
							<td>
								<input type="checkbox" value="{$item['status']}" name="status[]" data-id="{$item['id']}" {if $item['status'] == 1}checked{/if}>
							</td>
							<td style="text-align:right;">
								<a href="{php echo $this->createWebUrl('ptgoods', array('op' => 'list', 'cid' => $item['id']))}" class="btn btn-default btn-sm" title="查看商品" data-toggle="tooltip" data-placement="top"><i class="fa fa-eye"> </i></a>
								<a href="{php echo $this->createWebUrl('ptgoods', array('op' => 'post', 'cid' => $item['id']))}" class="btn btn-default btn-sm" title="添加商品" data-toggle="tooltip" data-placement="top" ><i class="fa fa-plus"> </i></a>
								<a href="{php echo $this->createWebUrl('ptcategory', array('op' => 'del', 'id' => $item['id']))}" class="btn btn-default btn-sm" title="删除" data-toggle="tooltip" data-placement="top" onclick="if(!confirm('删除后该分类下的商品也会删除，确定删除吗?')) return false;"><i class="fa fa-times"> </i></a>
							</td>
						</tr>
						{/loop}
					</tbody>
				</table>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-12">
				<input name="token" type="hidden" value="{$_W['token']}" />
				<input type="submit" class="btn btn-primary col-lg-1" name="submit" value="提交" />
			</div>
		</div>
		{$pager}
	</form>
</div>
<script type="text/javascript">
require(['bootstrap.switch'], function($){
	$('.form-file').submit(function(){
		if(!$(':file[name="file"]').val()) {
			util.message('请先上传要导入的文件', '', 'error');
			return false;
		}
	});

	$(':checkbox[name="status[]"]').bootstrapSwitch();
	$(':checkbox[name="status[]"]').on('switchChange.bootstrapSwitch', function(e, state){
		var status = this.checked ? 1 : 0;
		var id = $(this).data('id');
		$.post("{php echo $this->createWebUrl('ptcategory', array('op' => 'status'))}", {status: status, id: id}, function(resp){
			setTimeout(function(){
				location.reload();
			}, 500)
		});
	});
});
</script>
{/if}
{template 'common'}
{template 'public/footer'}